# -*- coding:utf-8 -*-
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution:
    def FindKthToTail(self, head, k):
        # write code here
        if head==None or k==0:
            return None
        f = l = head
        while k-1>0:
            if f.next!=None:
                f = f.next
                k-=1
            else:
                return None
        while f.next!=None:
            f = f.next
            l = l.next
        return l


node1 = ListNode(1)
node2 = ListNode(2)
node3 = ListNode(3)
node4 = ListNode(4)
node5 = ListNode(5)
node6 = ListNode(6)
node7 = ListNode(7)
node1.next = node2
node2.next = node3
node3.next = node4
node4.next = node5
node5.next = node6
node6.next = node7


s = Solution()
m= s.FindKthToTail(node1,3)
print(m.val)